package feiyanren.com;

public class A04_Demo4 {
    public static void main(String[] args) {
        int[] arr = {1,2,3,4,5};
        int target = 5;
        int index = find(arr,target);
        System.out.println(index);

    }
    public static int find(int[] arr,int target){
        int start = 0;
        int end = arr.length-1;
        while(true){
            if(start > end){
                return -1;
            }
            int mid = start + (target - arr[start])/(arr[end] - arr[start])*(end - start);
            if(arr[mid] == target){
                return mid;
            }
            else if(arr[mid] > target){
                end = mid - 1;
            }
            else{
                start = mid + 1;
            }
        }
    }
}
